let express=require("express");
let bodyParser=require("body-parser");
let app=new express();

//2.body-parser添加到项目app中去,把bodyParser注册到APP下面去
app.use(bodyParser.urlencoded({ extended: false }))  //false接收的值为字符串或者数组，true则为任意类型
// parse application/json    
app.use(bodyParser.json())   //解析json格式

app.get('/',(req,res)=>{
  res.send("/首页");
});

app.get("/ajax",(req,res)=>{
  res.setHeader("Access-Control-Allow-Origin","*");
   // 拿到客户端传递过来的参数
  //  let result=JSON.parse(req.query);
  let result=req.query;
   console.log(result);
   res.send(result)
});

app.get("/get",(req,res)=>{
  res.setHeader("Access-Control-Allow-Origin","*");
  let result=req.query;
  res.send(result);
});

app.post("/post",(req,res)=>{
  res.setHeader("Access-Control-Allow-Origin","*");
  let result=req.body;
  console.log(result);
  res.send(result);
});

let port=8000;

app.listen(port,()=>{
  console.log("你正在监听的是"+port+"端口");
})


